package com.gams.springboot.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gams.springboot.pojo.User;
import org.apache.ibatis.annotations.*;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author tql
 * @current springboot
 * @create 2021-09-2-10:35
 */
@Mapper
public interface UserDao  {
    //查询所有用户
    @Select("select * from sys_user")
    List<User> getUserList();

    @Insert("insert into sys_user(name,account,password," +
            "status,createTime,updateTime)values(#{name},#{account},#{password},#{status},#{createTime},#{updateTime});")
    int addUser(User user);

    @Select("select count(*) from sys_user where name=#{name} and password=#{password}")
    int selectUser(String name,String password);

    @Delete("delete from sys_user where id=#{id}")
    int deleteUser(long id);

    @Select("select * from sys_user where name=#{name}")
    User selectUserByName(String name);

    @Update("update sys_user set name=#{name},account=#{account},status=#{status},createTime=#{createTime},updateTime=#{updateTime} where id=#{id}")
    int updateUser(User user);

    @Insert("insert into user_role(userId,roleId)values (#{userId},#{roleId})")
    int insertUserRole(long userId,long roleId);

    @Select("select id from sys_user where name = #{name}")
    int queryId(String name);

    @Select("select roleId from user_role where userId = #{userId} ")
    List<Long> selectRoleIdByUserId(long userId);

    @Delete("delete from user_role where userId=#{id} ")
    int deleteUserRoleById(long id);

    @Update("update sys_user set password = #{password} where id=#{id}")
    int updateUserPassword(String password,long id);

    List<User> searchUser(Map<String,Object> map);

}
